﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Diagnostics;

[assembly: log4net.Config.XmlConfigurator(Watch = true)]
namespace MiGuava
{
    static class Program
    {
        private static readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        //public static readonly log4net.ILog logger = log4net.LogManager.GetLogger("MiGuava.FileLogger");
        public static frmMain fMainForm;

        public static string DialogTitle = "采掘接续计划智能编制系统 1.0";
        
        public static string VersionSuffix = "";

        public static string C_RegistrySectionKey = "Software\\DarkMi-Software\\Mining-Excavation-Plan-Compile-System\\Settings";

        public static System.Globalization.CultureInfo StartUpUICulture;

        public static SqlServer.GanttSqlDB SqlDB = null;

        public static object GetMySetting(string ValueKey, object DefaultValue)
        {
            object returnValue;
            KS.Common.KSRegistry cReg = new KS.Common.KSRegistry();
            cReg.sectionKey = C_RegistrySectionKey;
            cReg.valueKey = ValueKey;
            cReg.defaultValue = DefaultValue;
            returnValue = cReg.value;
            return returnValue;
        }

        public static void SaveMySetting(string ValueKey, object Value)
        {
            KS.Common.KSRegistry cReg = new KS.Common.KSRegistry();
            cReg.sectionKey = C_RegistrySectionKey;
            cReg.valueKey = ValueKey;
            cReg.value = Value;
        }

        public static void CursorWait()
        {
            Cursor.Current = Cursors.WaitCursor;
        }

        public static void CursorDefault()
        {
            Cursor.Current = Cursors.Default;
        }

        public static void ErrMsgBox(string S)
        {
            MessageBox.Show(S, DialogTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }

        public static void InfoMsgBox(string S)
        {
            MessageBox.Show(S, DialogTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        public static DialogResult QuestionMsgBox(string S)
        {
            return MessageBox.Show(S, DialogTitle, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
        }

        public static void OpenURL(string strURL)
        {
            if (strURL != "")
            {
                try
                {
                    Process.Start(strURL);
                }
                catch (Exception ex)
                {
                    ErrMsgBox(ex.Message);
                }
            }
        }

        /// <summary>
        /// Der Haupteinstiegspunkt für die Anwendung.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            //MessageBox.Show("begin");
            logger.Debug("Debug logging");
            logger.Info("Info logging");
            logger.Warn("Warn logging");
            logger.Error("Error logging");
            logger.Fatal("Fatal error logging");
            //MessageBox.Show("end");

            CursorWait();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            StartUpUICulture = System.Threading.Thread.CurrentThread.CurrentUICulture;            

            string strGUILanguage = KS.Common.Strings.GetSafeString(GetMySetting("GUILanguage", ""));

            switch (strGUILanguage)
            {
                case "en":
                    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
                    break;

                case "zh-CHS":
                    //System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CHS");
                    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN");
                    break;

                default:
                    if (System.Threading.Thread.CurrentThread.CurrentUICulture.Name.StartsWith("zh"))
                        //System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CHS");
                        System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN");
                    else
                        System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");

                    break;
            }

            fMainForm = new frmMain();

            Application.Run(fMainForm);
        }
    }
}